package pl.streamsoft.currencyApp.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	private SessionFactory sessionFactory;
	private Session session;
	
	public HibernateUtil(){
		sessionFactory = new Configuration().configure().buildSessionFactory();
	}
	
	public Session getOpenedSession(){
		session = sessionFactory.openSession();
		session.beginTransaction();
		return session;
	}
	
	public void closeSession(){
		session.getTransaction().commit();
		session.close();
	}
	
	public void rollBackTransaction(){
		session.getTransaction().rollback();
		session.close();
	}
}
